package com.burger.burgerpicturebackend.service.impl;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.burger.burgerpicturebackend.model.dto.tags.TagsQueryRequest;
import com.burger.burgerpicturebackend.model.entity.Space;
import com.burger.burgerpicturebackend.model.entity.Tags;
import com.burger.burgerpicturebackend.service.TagsService;
import com.burger.burgerpicturebackend.mapper.TagsMapper;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author zjb13
 * @description 针对表【tags】的数据库操作Service实现
 * @createDate 2025-01-21 00:17:41
 */
@Service
public class TagsServiceImpl extends ServiceImpl<TagsMapper, Tags>
        implements TagsService {

    @Override
    public QueryWrapper<Tags> getQueryWrapper(TagsQueryRequest tagsQueryRequest) {
        QueryWrapper<Tags> queryWrapper = new QueryWrapper<>();
        if (tagsQueryRequest == null) {
            return queryWrapper;
        }
        Long tagId = tagsQueryRequest.getTagId();
        String tagName = tagsQueryRequest.getTagName();
        String sortField = tagsQueryRequest.getSortField();
        String sortOrder = tagsQueryRequest.getSortOrder();
        // 拼接查询条件
        queryWrapper.eq(ObjUtil.isNotEmpty(tagId), "tagId", tagId);
        queryWrapper.like(StrUtil.isNotBlank(tagName), "tagName", tagName);
        // 排序
        queryWrapper.orderBy(StrUtil.isNotEmpty(sortField), sortOrder.equals("ascend"), sortField);
        return queryWrapper;
    }
}




